package com.njtoyo.taxi.admin.rest.controller.platform;

import com.njtoyo.taxi.admin.aop.PassToken;
import com.njtoyo.taxi.admin.mapper.secondary.enums.VersionModel;
import com.njtoyo.taxi.admin.mapper.secondary.enums.VersionUserGroup;
import com.njtoyo.taxi.admin.rest.wrapper.platform.appVersion.AppVersionWrapper;
import com.njtoyo.taxi.admin.service.platform.VersionService;
import com.taxi.entity.common.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/platform/app-version")
public class VersionController {

    @Autowired
    private VersionService appVersionService;


    @GetMapping("/list")
    @PassToken
    public RestResult list(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                           @RequestParam(value = "size", required = false, defaultValue = "15") Integer size,
                           @RequestParam(value = "title", required = false) String title,
                           @RequestParam(value = "model", required = false) VersionModel model,
                           @RequestParam(value = "userGroup", required = false) VersionUserGroup userGroup) {
        return appVersionService.list(current, size, title, model, userGroup);
    }


    @PostMapping("/uploadApp")
    @PassToken
    RestResult upload(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return RestResult.failed("不能上传空文件");
        }
        return appVersionService.uploadApp(file);
    }

    @GetMapping("/{id}/info")
    RestResult getVersionInfo(@PathVariable("id") Long id) {
        return appVersionService.getVersionInfo(id);
    }


    @PostMapping("/add")
    RestResult add(@RequestBody AppVersionWrapper appVersionWrapper) {
        return appVersionService.add(appVersionWrapper);
    }

    @PostMapping("/update")
    RestResult updateById(@RequestBody AppVersionWrapper appVersionWrapper) {
        return appVersionService.updateById(appVersionWrapper);
    }


}
